package com.situ.web.servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/servletContext")
public class ServletContextServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		ServletContext servletContext = getServletContext();
		// 1、a.txt
		// Servlet是运行在服务器端的代码，"/"代表当前tomcat上面运行的项目
		String aPath = servletContext.getRealPath("/WEB-INF/classes/a.txt");
		// C:\apache-tomcat-8.5.42\webapps\JavaWeb1907\WEB-INF\classes\a.txt
		System.out.println(aPath);
		// 2、b.txt
		String bPath = servletContext.getRealPath("/b.txt");
		// C:\apache-tomcat-8.5.42\webapps\JavaWeb1907\b.txt
		System.out.println(bPath);
		// 3、c.txt
		String cPath = servletContext.getRealPath("/WEB-INF/c.txt");
		// C:\apache-tomcat-8.5.42\webapps\JavaWeb1907\WEB-INF\c.txt
		System.out.println(cPath);
	}
}
